﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Concat
{
    class ParseException : Exception
    {
        public Token token;

        public ParseException(string message, Token token)
            : base(message.Replace("{loc}", token.loc.ToString()))
        {
            this.token = token;
        }
    }

    class InvalidTokenException : ParseException
    {
        public InvalidTokenException(Token token)
            : base("Invalid token at {loc}.", token)
        {
        }
    }
    class MismatchedBracketException : ParseException
    {
        public LeftBracketToken bracket;

        public MismatchedBracketException(LeftBracketToken bracket)
            : base("Mismatched bracket starting at {loc}.", bracket)
        {
            this.bracket = bracket;
        }
    }
    class MissingNameException : ParseException
    {
        public MissingNameException(Token token)
            : base("Missing name in definition at {loc}.", token)
        {
        }
    }
    class MissingBodyException : ParseException
    {
        public MissingBodyException(Token token)
            : base("Missing body in word definition at {loc}.", token)
        {
        }
    }
    class DuplicateFormalException : ParseException
    {
        public string formal;

        public DuplicateFormalException(string formal, Token token)
            : base("Duplicate formal parameter '" + formal + "' at {loc}.", token)
        {
            this.formal = formal;
        }
    }
    class DuplicateSlotException : ParseException
    {
        public string slot;

        public DuplicateSlotException(string slot, Token token)
            : base("Duplicate slot name '" + slot + "' at {loc}.", token)
        {
            this.slot = slot;
        }
    }
    class DuplicateParamException : ParseException
    {
        public string param;

        public DuplicateParamException(string param, Token token)
            : base("Duplicate paremeter name '" + param + "' at {loc}.", token)
        {
            this.param = param;
        }
    }
    class ExpectedCurlyBracketException : ParseException
    {
        public ExpectedCurlyBracketException(Token token)
            : base("Expected curly bracket at {loc}.", token)
        {
        }
    }
}
